package com.saunter.utils.exception;

import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@PropertySource(value = {"classpath:config/exception.properties"}, encoding = "UTF-8")
public class ExceptionManager {
    @Resource
    private Environment environment;
    public CustomException create(String code) {
        return this.create(code, null);
    }
    public CustomException create(String code, Object data) {
        String err_msg = environment.getProperty(""+code);
        return new CustomException(code, err_msg==null ? "未知异常" : err_msg, data);
    }
}
